﻿using System;

namespace HaroModuleLib
{
    /// <summary>
    /// Defines a generalized host to a set of modules and accomodates basic functions
    /// that need to be implemented.
    /// </summary>
    public interface IModuleHost
    {
        /// <summary>
        /// Unloads the specified module.
        /// </summary>
        /// <param name="m">A reference to the IModule which is used as signature to verify the module's identity.</param>
        void UnloadModule(IModule m);

        /// <summary>
        /// Loads the specified grammar file into the speech recognition engine.
        /// </summary>
        /// <param name="m">A reference to the IModule which is used as signature to verify the module's identity.</param>
        /// <param name="GrammarFileAddress"></param>
        string LoadGrammar(IModule m, string GrammarFileAddress);

        /// <summary>
        /// Unloads the grammar pertaining to this module.
        /// </summary>
        /// <param name="m">A reference to the IModule which is used as signature to verify the module's identity.</param>
        void UnloadGrammar(IModule m);

        /// <summary>
        /// Reloads the grammar pertaining to this module.
        /// </summary>
        /// <param name="m">A reference to the IModule which is used as signature to verify the module's identity.</param>
        void ReloadGrammar(IModule m);
 
        /// <summary>
        /// Sends a string message to the specified module.
        /// </summary>
        /// <param name="ToModuleName">Name of the module that will be messaged.</param>
        /// <param name="Message">String containing the message to be sent.</param>
        void SendMessage(string ToModuleName, string Message);

        /// <summary>
        /// Receive a debug statement from a module that can be handled by the IModuleHost.
        /// </summary>
        /// <param name="FromModuleName">Name of the module that the debug message is arriving from.</param>
        /// <param name="DebugMessage">String containing the debug message.</param>
        void DebugMessage(string FromModuleName, string DebugMessage);

        /// <summary>
        /// Allows for the loading of settings from the specified path and utilizes the XMLSerializer.
        /// </summary>
        /// <param name="SettingsPath">String containing the path of the xml file containing
        /// the settings information.</param>
        /// <param name="t">Type defining the object that needs to be loaded.</param>
        /// <returns>Returns the object created from the settings found in SettingsPath.</returns>
        object LoadSettings(string SettingsPath, Type t);

        /// <summary>
        /// Allows for the saving of settings to the specified path and utilizes the XMLSerializer.
        /// </summary>
        /// <param name="SettingsPath">String containing the path of the xml file in which the
        /// class data will be stored.</param>
        /// <param name="t">Type defining the object that needs to be saved.</param>
        /// <param name="o">Object from which the data will be extrapolated and saved.</param>
        void SaveSettings(string SettingsPath, Type t, object o);
    }

    /// <summary>
    /// Defines a generic module with standardized functions and properties.
    /// </summary>
    public interface IModule
    {
        /// <summary>
        /// Gets the name of the module.
        /// </summary>
        string Name { get; }

        /// <summary>
        /// Gets the name of the author(s) of the module.
        /// </summary>
        string Author { get; }

        /// <summary>
        /// Gets a description of the module.
        /// </summary>
        string Description { get; }
        
        /// <summary>
        /// Gets or sets the host for this module.
        /// </summary>
        IModuleHost Host { get; }

        /// <summary>
        /// Called after the IModule is instantiated in order to allow the module to load
        /// and initialize all necessary resources and pre-requisites.
        /// </summary>
        void OnLoad(IModuleHost Host);

        /// <summary>
        /// Called to signal the module to start its normal processes.
        /// </summary>
        void Start();

        /// <summary>
        /// Called when a message is sent to the module.
        /// </summary>
        /// <param name="Message">String containing the message sent.</param>
        void OnMessaged(string Message);

        /// <summary>
        /// Called previous to the Dispose function to allow the module to unload all data
        /// before the dispose stage.
        /// </summary>
        void OnUnload();

        /// <summary>
        /// Called after OnUnload to allow for disposal of any memory being occupted by the module.
        /// </summary>
        void Dispose();
    }
}
